﻿using ByHand.Model;
using ByHand.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BackEnd.Controllers
{
    public class LogController : Controller
    {
        private readonly ILogService _LogService;
        private readonly IOrderService _OrderService;
        public LogController(ILogService LogService, IOrderService OrderService)
        {
            _LogService = LogService;
            _OrderService = OrderService;
        }
        public ActionResult Index(string page, string filter)
        {
            if (string.IsNullOrWhiteSpace(page))
            {
                page = "1";
            }
            ViewData["tableindex"] = new { page = page, pagesize = Convert.ToInt32(Resources.Resource.ItemPerPage), filter = filter };
            return View();
        }
        public ActionResult TableLog(int page, int pagesize, string filter)
        {
            int total = 0;
            pagesize = Convert.ToInt32(Resources.Resource.ItemPerPage);
            if (page == 0)
            {
                page = 1;
            }
            var model = new List<Log>();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                model = _LogService.GetByPageFilter(page, pagesize, out total, filter);
                ViewData["filter"] = filter;
            }
            else
            {
                model = _LogService.GetByPage(page, pagesize, out total);
            }
            if ((total % pagesize) > 0)
            {
                ViewData["total"] = (total / pagesize) + 1;
            }
            else
            {
                ViewData["total"] = total / pagesize;
            }

            ViewData["curpage"] = page;
            ViewData["nextpage"] = page + 1;
            ViewData["prepage"] = page - 1;
            return PartialView(model);
        }
        public ActionResult Details(int id)
        {
            var log = _LogService.GetById(id);
            return PartialView(log);
        }

    }
}
